<?php
namespace Admin\Controller;
use Think\Controller;
class CommonController extends Controller{
        public function __construct()
        {
            parent::__construct();
            $this->check_login();
        }

    protected function check_login()

    {

        if(isset($_SESSION['user'])){
            $this->assign('user', $_SESSION['user']);
            return;
        }

        if($data['token'] = $_COOKIE['token']){
            $User1 = M('User');
            $user = $User1->where($data)->find();
            //dump($user);
            //echo $User1->getLastSql();
            if($user){
                $this->assign('user', $user);
                return;
            }else{
                $this->error('非法用户！',U('User/logout'));
            }
        }

        $this->error('非法用户！',U('User/logout'));
    }
}






/*
        if (isset($token)) {
            $Uer = M('User');
            $user = $Uer->where($condition)->find();
            $this->assign('user', $user);
return;
        }else{
            if (!isset($_SESSION['user'])) {
                $this->error('请您登录！', U('Admin/User/login'));
return;
            }else{
                $this->assign('user',$_SESSION['user']);
            }
        }
    }*/
